<?php
	
autoLoader();

// display( $_REQUEST );
// display( $_POST ); exit;

if( false == isset( $_POST['Submit'] ) || false == valStr( $_POST['patient_id'] ) ) { 
	$str = '';
	$str .= '<form name=myform method=post action=modules.php?file=charges&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
	$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
	echo $str;
	exit;
}

if( true == isset( $_POST['operation'] ) && 'insert' == strtolower( $_POST['operation'] ) ) {
	$objBaseCharges 	 = new BaseCharges();

	$objBaseCharges->setChargeTypeId( $_POST['charge_type_id'] );
	$objBaseCharges->setChargeCatagoryId( $_POST['charge_catagory_id'] );
	$objBaseCharges->setMinAmount( $_POST['min_amount'] );
	$objBaseCharges->setMaxAmount( $_POST['max_amount'] );
	$objBaseCharges->setRate( $_POST['rate'] );
	$objBaseCharges->setDepartmentId( $_POST['department_id'] );
	$objBaseCharges->setPatientId( $_POST['patient_id'] );
	
    $objBaseCharges->setDeletedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setDeletedOn( 'now()' );
	$objBaseCharges->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseCharges->insert() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_charges&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
} else if( true == isset( $_POST['operation'] ) && 'update' == strtolower( $_POST['operation'] ) ) {

	$objCharges = new Charges();
	$objBaseCharges 	= $objCharges->fetchChargesById( $_POST['charge_id'] );
	
	$objBaseCharges->setChargeTypeId( $_POST['charge_type_id'] );
	$objBaseCharges->setChargeCatagoryId( $_POST['charge_catagory_id'] );
	$objBaseCharges->setMinAmount( $_POST['min_amount'] );
	$objBaseCharges->setMaxAmount( $_POST['max_amount'] );
	$objBaseCharges->setRate( $_POST['rate'] );
	$objBaseCharges->setDepartmentId( $_POST['department_id'] );
	$objBaseCharges->setPatientId( $_POST['patient_id'] );

    $objBaseCharges->setDeletedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setDeletedOn( 'now()' );
	$objBaseCharges->setCreatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setUpdatedBy( ( true == isset( $_SESSION['SESS_MEMBER_ID'] ) ) ? $_SESSION['SESS_MEMBER_ID'] : 1 );
	$objBaseCharges->setUpdatedOn( 'now()' );
	
	if( 1 == $objBaseCharges->update() ) {
		$str = '';
		$str .= '<form name=myform method=post action=modules.php?file=view_charges&type=view&mid=' . $_REQUEST['mid'] . '&smid=' . $_REQUEST['smid'] . '>';
		$str .= '<script language=JavaScript>document.myform.submit();</script></form>';
		echo $str;
		exit;
	}
}

?>